import { Router, Request, Response, NextFunction, RequestHandler } from 'express';
import {
    getInterestTags,
    createInterestTag,
    updateUserTags,
    getUserTags,
    searchTags,
} from '../controllers/interestTagController';
import { authenticate } from '../middleware/auth';

const router = Router();

// 获取所有兴趣标签
router.get('/', (async (req: Request, res: Response, next: NextFunction) => {
    try {
        await getInterestTags(req, res);
    } catch (error) {
        next(error);
    }
}) as RequestHandler);

// 搜索兴趣标签
router.get('/search', (async (req: Request, res: Response, next: NextFunction) => {
    try {
        await searchTags(req, res);
    } catch (error) {
        next(error);
    }
}) as RequestHandler);

// 创建新的兴趣标签（需要管理员权限）
router.post('/', authenticate, (async (req: Request, res: Response, next: NextFunction) => {
    try {
        await createInterestTag(req, res);
    } catch (error) {
        next(error);
    }
}) as RequestHandler);

// 更新用户的兴趣标签
router.put('/user', authenticate, (async (req: Request, res: Response, next: NextFunction) => {
    try {
        await updateUserTags(req, res);
    } catch (error) {
        next(error);
    }
}) as RequestHandler);

// 获取用户的兴趣标签
router.get('/user/:userId', (async (req: Request, res: Response, next: NextFunction) => {
    try {
        await getUserTags(req, res);
    } catch (error) {
        next(error);
    }
}) as RequestHandler);

export default router; 